(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/ts/Game.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, 'be728fLBlNFoaV31hHAOks9', 'Game', __filename);
// ts/Game.ts

Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var Game = (function (_super) {
    __extends(Game, _super);
    function Game() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.mainBox = null;
        _this.timeLabel = null;
        _this.number = null;
        _this.startData = [];
        _this.residueData = [];
        _this.numberBoxList = null;
        _this.cur_num = 1;
        _this.time = 0;
        return _this;
    }
    Game.prototype.onLoad = function () {
        this.mainBox.width = cc.winSize.width - 40;
        this.mainBox.height = this.mainBox.width;
        this.timeLabel.node.setPosition(-cc.winSize.width / 2 + this.timeLabel.node.width / 2 + 20, cc.winSize.height / 2 - this.timeLabel.node.height / 2 - 20);
        this.get_start_initData();
        var index = 0;
        for (var y = 0; y < 5; y++) {
            for (var x = 0; x < 5; x++) {
                var numberBox = cc.instantiate(this.number);
                numberBox.getComponent("NumberBox").game = this;
                numberBox.getComponent("NumberBox").set_text(this.startData[index]);
                numberBox.width = (this.mainBox.width - 30) / 5;
                numberBox.height = (this.mainBox.height - 30) / 5;
                var n_x = 5 + (5 + numberBox.width) * x + numberBox.width / 2;
                var n_y = 5 + (5 + numberBox.height) * y + numberBox.height / 2;
                numberBox.scaleX = 0;
                numberBox.scaleY = 0;
                numberBox.setPosition(n_x, n_y + cc.winSize.height);
                //numberBox.setPosition(n_x, n_y);
                var action = cc.spawn(cc.scaleTo(0.05 * index + 0.1, 1, 1), cc.moveTo(0.05 * index + 0.1, cc.v2(n_x, n_y)).easing(cc.easeCircleActionIn()));
                numberBox.runAction(action);
                this.numberBoxList[x][y] = numberBox;
                numberBox.getComponent("NumberBox").setArrPosition(x, y);
                this.mainBox.addChild(numberBox);
                index++;
            }
        }
    };
    Game.prototype.number_click = function (x, y) {
        var numberBox = this.numberBoxList[x][y];
        var c_num = numberBox.getComponent("NumberBox").num;
        if (c_num == this.cur_num) {
            var num = this.residueData[0];
            if (num) {
                numberBox.getComponent("NumberBox").set_text(num);
                this.residueData.shift();
            }
            else {
                this.mainBox.removeChild(numberBox);
            }
            if (c_num == 1) {
                this.start_game();
            }
            if (c_num == 50) {
                this.end_game();
            }
            this.cur_num++;
        }
        else {
            cc.log("点击数字不对");
        }
    };
    Game.prototype.start_game = function () {
        this.schedule(this.time_add, 0.001);
    };
    Game.prototype.end_game = function () {
        this.unschedule(this.time_add);
        this.mainBox.runAction(cc.hide());
        this.timeLabel.node.runAction(cc.spawn(cc.moveTo(1, 0, 0), cc.scaleTo(1, 1)));
    };
    Game.prototype.time_add = function () {
        this.time++;
        this.timeLabel.string = (this.time / 60).toFixed(3);
    };
    Game.prototype.get_start_initData = function () {
        var arr = [];
        for (var num = 1; num <= 25; num++) {
            arr.push(num);
        }
        this.startData = arr.sort(this.randomsort);
        var arr = [];
        for (var num = 26; num <= 50; num++) {
            arr.push(num);
        }
        this.residueData = arr.sort(this.randomsort);
        // 初始化方块数组
        this.numberBoxList = [
            [null, null, null, null, null],
            [null, null, null, null, null],
            [null, null, null, null, null],
            [null, null, null, null, null],
            [null, null, null, null, null]
        ];
    };
    Game.prototype.randomsort = function (a, b) {
        return Math.random() > .5 ? -1 : 1;
    };
    __decorate([
        property(cc.Node)
    ], Game.prototype, "mainBox", void 0);
    __decorate([
        property(cc.Label)
    ], Game.prototype, "timeLabel", void 0);
    __decorate([
        property(cc.Prefab)
    ], Game.prototype, "number", void 0);
    Game = __decorate([
        ccclass
    ], Game);
    return Game;
}(cc.Component));
exports.default = Game;

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=Game.js.map
        